#ifndef ACTIONFILEWRITER_H
#define ACTIONFILEWRITER_H

#include "robotaction.h"
#include <QFile>
#include <QTextStream>

/**
 * @brief Writes TiLAR action files.
 *
 * This class is responsible for writing RobotActions to disk in as
 * a TiLAR action file (.taf).  It has one static method, write(),
 * which parses a RobotAction object and writes to the given filename.
 *
 * There is a big assumption being made when we write the information
 * to the current TiLAR action file format.  Namely, we assume that
 * each key frame has positions defined for every "active" joint in
 * the action (i.e., joint "19" can't have just one key frame if
 * joint "18" has two.  They must both have two at the same timestamps).
 * This is not the native behavior of the data structures underneath.
 * The RobotAction class stores the key frames for each joint as
 * independent from every other joint - which is a more powerful solution
 * - but our file format is not written to support that functionality.
 * In fact, it introduces problems because a robust file writer will
 * require advanced error checking and logic to insert "fake" key
 * values for joints that don't have key frames at a given timestamp.  So,
 * right now, we have a brittle, simple solution, which makes the above
 * assumption.
 *
 * The interesting thing about inserting "fake" key values into the file
 * format is that they would be read in as real ones, and so after
 * one write/read iteration, the action would be populated by fake key
 * values and we wouldn't need the error checking for the next write.
*/
class ActionFileWriter
{
public:
    ActionFileWriter();

    static void write(QString filename, RobotAction* action);
    static void writeLegacyFile(QString filename, RobotAction* action);
};

//These functions have been declared as friends to the RobotAction class
//and its related classes to make serialization easier
QTextStream &operator<<(QTextStream &out, const RobotAction &action);
QDataStream &operator<<(QDataStream &out, const RobotAction &action);

#endif // ACTIONFILEWRITER_H
